package GameMain.View.MsgBox
{
	import Engine.Module.ModuleBase;
	
	import GameMain.Game;
	
	import flash.display.Sprite;
	import flash.text.TextField;
	
	public class MsgBox extends ModuleBase
	{
		private static const ONE_CLICK:int = 1;
		private static const TWO_CLICK:int = 2;
		
		private var _msgTxt:TextField;
		private var _okBtn:Sprite;
		private var _cancelBtn:Sprite;
		private var _backFun:Function = null;
		
		public function MsgBox(p_content:Sprite=null)
		{
			super(p_content);
			this.x = 350;this.y = 250;
			this._msgTxt = this._content["MSG_TXT"];
			this._okBtn = this._content["OK_BTN"];
			this._cancelBtn = this._content["CANCEL_BTN"];
			Game.ControlMgr.getButton(this._okBtn).setOnClickFun(this.onClickOK);
			Game.ControlMgr.getButton(this._cancelBtn).setOnClickFun(this.onClickCancel);
		}
		
		public function ShowMsg(msgTxt:String,backFun:Function,state:int):void
		{
			this._msgTxt.text = msgTxt;
			if(this._backFun != null)
				this._backFun(0);
			this._backFun = backFun;
			if (state == ONE_CLICK)
			{
				this._cancelBtn.visible = false;
				this._okBtn.x = 101.3;
			}
			else
			{
				this._cancelBtn.visible = true;
				this._okBtn.x = 30.35;
			}
		}
		
		private function onClickOK():void
		{
			this.onClickOver(1)
		}
		
		private function onClickCancel():void
		{
			this.onClickOver(0)
		}
		
		private function onClickOver(state:int):void
		{
			if(this._backFun != null)
				this._backFun(state);
			this._backFun = null;
			this.dispose();
		}
	}
}